Behaviour and State Change Models

 

 

1.      Write a short, simple scenario to describe what happens when a caller tries to obtain a phone number by calling Directory Enquiries, but the operator can’t find the number and has to ask the caller to spell the name in order to find it. Draw a sequence diagram to illustrate the scenario.

 

2.      Draw a statechart summarising the information given in the following description of some of the events that can arise in the life cycle of a thread in Java.


When a thread is created, it does not start running immediately, but is left in the New Thread state. When the thread is in this state, it can only be started or stopped. Calling any method besides start or stop makes no sense, and causes an exception to be raised. The start method causes system resources to be allocated to the thread, and calls the thread's run method. At this point the thread is in the Running state. A thread becomes not runnable if either its sleep or suspend methods are called. The sleep method has a parameter specifying the length of time the thread should sleep for; when this time has elapsed the thread starts to run again. If the suspend method has been called, the thread only runs again when its resume method is called. A thread can die in two ways. It dies naturally when its run method exits normally. A thread can also be killed at any time by calling its stop method.

 

3.      Consider a digital watch with two buttons: A and B. When the watch is in the normal mode, pressing A toggles the time display between 12 and 24 hour format, while pressing B illuminates the watch display. If you keep A pressed for more than 3 seconds, then the watch goes into set mode, which allows you to adjust the time. The adjustment of the hours and the minutes takes place separately and you can toggle between them by pressing the B button. The current selection is indicated by the flashing of the respective part (i.e. the hours or minutes). In set mode pressing button A increments the currently selected part by one. In order to return to the normal mode the user needs to press A for more than 3 seconds. When returning back into normal mode the watch displays time in the last used format (12 or 24 hour). The adjustment of time is always in 24 hour format. Construct a statechart representing the behaviour of the digital watch.